package algorithm;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * 冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args) {

        int[] data = { 9, -16, 21, 23, -30, -49, 21, 30, 30 };

        for (int i = 0; i < data.length-1; i++) {
            for (int j = 0; j < data.length - i - 1; j++) {
                if (data[j]>data[j+1]){
                    int tmp = data[j+1];
                    data[j+1]=data[j];
                    data[j]=tmp;
                }
            }
        }



        System.out.println(Arrays.toString(data));


        Set set = new TreeSet(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2)==0 ? 1:o1.compareTo(o2);
            }
        });

        for (int datum : data) {
            set.add(datum);
        }

        System.err.println(set);
    }

}
